package lj.fx.main;

import cn.hutool.log.StaticLog;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import lj.fx.tool.base.BaseCtl;
import lj.fx.tool.base.FactoryCtl;
import lombok.Data;

/**
 * @author: liuwenju
 * @date: 2023/6/26 9:21
 * @version: 1.0
 */
@Data
public class FxMainCtl extends BaseCtl {

    @FXML
    private Button btn;
    @FXML
    private ListView<String> list;

    @Override
    public void onInit() {
        ObservableList<String> objlist = FXCollections.observableArrayList();
        objlist.add("data1");
        objlist.add("data2");
        objlist.add("data3");
        objlist.add("data4");
        objlist.add("data5");
        list.setItems(objlist);

        list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                System.out.println("选中了：" + newValue);
            }
        });

        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                StaticLog.info("点击了[{}]");
                FxMain.toolStage.openStage("lj.fx.main/fx-other.fxml");
            }
        });
    }
}
